import { useMutation, useQuery } from "react-query";
import { CaptchData } from "types/captcha";
import { LoginParams } from "types/login";
import { useHttp } from "./http";

export const useLogin = () => {
  const client = useHttp();

  return useMutation((params: LoginParams) =>
    client(`login`, {
      data: params,
      method: "POST",
    })
  );
};

export const useCaptcha = (param?: { time: number }) => {
  const client = useHttp();
  return useQuery<CaptchData>(["captcha", param], () =>
    client(`captcha`, {
      data: param,
    })
  );
};
